﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Common.OpenXml
{
    /// <summary>
    /// predefined 3d feel for basic chart
    /// </summary>
    public class ChartStyleHelper
    {
        /// <summary>
        /// style is applied last within plotArea node 
        /// </summary>
        /// <param name="writer"></param>
        public static void AddPlotAreaStyle(XmlWriter writer)
        {
            writer.WriteStartElement(Prefixes.ChartML, "spPr", Namespaces.ChartML);

            // gradient 
            writer.WriteStartElement(Prefixes.DrawingML, "gradFill", Namespaces.DrawingML);
            writer.WriteStartElement(Prefixes.DrawingML, "gsLst", Namespaces.DrawingML);
            // gs 
            writer.WriteStartElement(Prefixes.DrawingML, "gs", Namespaces.DrawingML);
            writer.WriteAttributeString("pos", "0");
            writer.WriteStartElement(Prefixes.DrawingML, "srgbClr", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "8488C4");
            writer.WriteEndElement();//srgbClr
            writer.WriteEndElement();//gs
            // gs 
            writer.WriteStartElement(Prefixes.DrawingML, "gs", Namespaces.DrawingML);
            writer.WriteAttributeString("pos", "53000");
            writer.WriteStartElement(Prefixes.DrawingML, "srgbClr", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "D4DEFF");
            writer.WriteEndElement();//srgbClr
            writer.WriteEndElement();//gs
            // gs 
            writer.WriteStartElement(Prefixes.DrawingML, "gs", Namespaces.DrawingML);
            writer.WriteAttributeString("pos", "83000");
            writer.WriteStartElement(Prefixes.DrawingML, "srgbClr", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "D4DEFF");
            writer.WriteEndElement();//srgbClr
            writer.WriteEndElement();//gs
            // gs 
            writer.WriteStartElement(Prefixes.DrawingML, "gs", Namespaces.DrawingML);
            writer.WriteAttributeString("pos", "100000");
            writer.WriteStartElement(Prefixes.DrawingML, "srgbClr", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "96AB94");
            writer.WriteEndElement();//srgbClr
            writer.WriteEndElement();//gs
            writer.WriteEndElement();//gsLst

            writer.WriteStartElement(Prefixes.DrawingML, "lin", Namespaces.DrawingML);
            writer.WriteAttributeString("ang", "5400000");
            writer.WriteAttributeString("scaled", "0");
            writer.WriteEndElement();//lin
           
            writer.WriteEndElement();//gradFill

            // ln
            writer.WriteStartElement(Prefixes.DrawingML, "ln", Namespaces.DrawingML);
            writer.WriteStartElement(Prefixes.DrawingML, "gradFill", Namespaces.DrawingML);
            writer.WriteStartElement(Prefixes.DrawingML, "gsLst", Namespaces.DrawingML);
            // gs
            writer.WriteStartElement(Prefixes.DrawingML, "gs", Namespaces.DrawingML);
            writer.WriteAttributeString("pos", "0");
            writer.WriteStartElement(Prefixes.DrawingML, "schemeClr", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "accent1");
            writer.WriteStartElement(Prefixes.DrawingML, "tint", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "66000");
            writer.WriteEndElement();// tint
            writer.WriteStartElement(Prefixes.DrawingML, "satMod", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "160000");
            writer.WriteEndElement();//satMod
            writer.WriteEndElement();//schemeClr
            writer.WriteEndElement();//gs
            // gs
            writer.WriteStartElement(Prefixes.DrawingML, "gs", Namespaces.DrawingML);
            writer.WriteAttributeString("pos", "50000");
            writer.WriteStartElement(Prefixes.DrawingML, "schemeClr", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "accent1");
            writer.WriteStartElement(Prefixes.DrawingML, "tint", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "44500");
            writer.WriteEndElement();// tint
            writer.WriteStartElement(Prefixes.DrawingML, "satMod", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "160000");
            writer.WriteEndElement();//satMod
            writer.WriteEndElement();//schemeClr
            writer.WriteEndElement();//gs
            // gs
            writer.WriteStartElement(Prefixes.DrawingML, "gs", Namespaces.DrawingML);
            writer.WriteAttributeString("pos", "100000");
            writer.WriteStartElement(Prefixes.DrawingML, "schemeClr", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "accent1");
            writer.WriteStartElement(Prefixes.DrawingML, "tint", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "23500");
            writer.WriteEndElement();// tint
            writer.WriteStartElement(Prefixes.DrawingML, "satMod", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "160000");
            writer.WriteEndElement();//satMod
            writer.WriteEndElement();//schemeClr
            writer.WriteEndElement();//gs
            writer.WriteEndElement();//gsLst
            writer.WriteStartElement(Prefixes.DrawingML, "lin", Namespaces.DrawingML);
            writer.WriteAttributeString("ang", "5400000");
            writer.WriteAttributeString("scaled", "0");
            writer.WriteEndElement();//lin
            writer.WriteEndElement();//gradFill
            writer.WriteEndElement();//ln

            // effectLst
            writer.WriteStartElement(Prefixes.DrawingML, "effectLst", Namespaces.DrawingML);
            writer.WriteStartElement(Prefixes.DrawingML, "outerShdw", Namespaces.DrawingML);
            writer.WriteAttributeString("blurRad", "50800");
            writer.WriteAttributeString("dist", "38100");
            writer.WriteAttributeString("dir", "5400000");
            writer.WriteAttributeString("algn", "t");
            writer.WriteAttributeString("rotWithShape", "0");
            writer.WriteStartElement(Prefixes.DrawingML, "prstClr", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "black");
            writer.WriteStartElement(Prefixes.DrawingML, "alpha", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "40000");
            writer.WriteEndElement();//alpha
            writer.WriteEndElement();//prstClr
            writer.WriteEndElement();//outerShdw
            writer.WriteEndElement();//effectLst

            // scene3d
            writer.WriteStartElement(Prefixes.DrawingML, "scene3d", Namespaces.DrawingML);
            writer.WriteStartElement(Prefixes.DrawingML, "camera", Namespaces.DrawingML);
            writer.WriteAttributeString("prst", "orthographicFront");
            writer.WriteEndElement();//camera
            writer.WriteStartElement(Prefixes.DrawingML, "lightRig", Namespaces.DrawingML);
            writer.WriteAttributeString("rig", "threePt");
            writer.WriteAttributeString("dir", "t");
            writer.WriteEndElement();//lightRig
            writer.WriteEndElement();//scene3d

            // sp3d
            writer.WriteStartElement(Prefixes.DrawingML, "sp3d", Namespaces.DrawingML);
            writer.WriteStartElement(Prefixes.DrawingML, "bevelT", Namespaces.DrawingML);
            writer.WriteEndElement();//bevelT
            writer.WriteEndElement();//sp3d

            writer.WriteEndElement();//spPr
        }

        /// <summary>
        /// this is applied after chart within chartSpace node
        /// </summary>
        /// <param name="writer"></param>
        public static void AddChartspaceStyle(XmlWriter writer)
        {
            writer.WriteStartElement(Prefixes.ChartML, "roundedCorners", Namespaces.ChartML);
            writer.WriteAttributeString("val", "1");
            writer.WriteEndElement();//roundedCorners

            writer.WriteStartElement(Prefixes.ChartML, "spPr", Namespaces.ChartML);

            // gradFill
            writer.WriteStartElement(Prefixes.DrawingML, "gradFill", Namespaces.DrawingML);
            writer.WriteStartElement(Prefixes.DrawingML, "gsLst", Namespaces.DrawingML);
            // gs
            writer.WriteStartElement(Prefixes.DrawingML, "gs", Namespaces.DrawingML);
            writer.WriteAttributeString("pos", "0");
            writer.WriteStartElement(Prefixes.DrawingML, "srgbClr", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "FFEFD1");
            writer.WriteEndElement();//srgbClr
            writer.WriteEndElement();//gs
            // gs
            writer.WriteStartElement(Prefixes.DrawingML, "gs", Namespaces.DrawingML);
            writer.WriteAttributeString("pos", "64999");
            writer.WriteStartElement(Prefixes.DrawingML, "srgbClr", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "F0EBD5");
            writer.WriteEndElement();//srgbClr
            writer.WriteEndElement();//gs
            // gs
            writer.WriteStartElement(Prefixes.DrawingML, "gs", Namespaces.DrawingML);
            writer.WriteAttributeString("pos", "100000");
            writer.WriteStartElement(Prefixes.DrawingML, "srgbClr", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "D1C39F");
            writer.WriteEndElement();//srgbClr
            writer.WriteEndElement();//gs
            writer.WriteEndElement();//gsLst
            writer.WriteStartElement(Prefixes.DrawingML, "lin", Namespaces.DrawingML);
            writer.WriteAttributeString("ang", "5400000");
            writer.WriteAttributeString("scaled", "0");
            writer.WriteEndElement();//lin
            writer.WriteEndElement();//gradFill

            // effectLst
            writer.WriteStartElement(Prefixes.DrawingML, "effectLst", Namespaces.DrawingML);
            writer.WriteStartElement(Prefixes.DrawingML, "outerShdw", Namespaces.DrawingML);
            writer.WriteAttributeString("blurRad", "50800");
            writer.WriteAttributeString("dist", "38100");
            writer.WriteAttributeString("dir", "2700000");
            writer.WriteAttributeString("algn", "tl");
            writer.WriteAttributeString("rotWithShape", "0");
            writer.WriteStartElement(Prefixes.DrawingML, "prstClr", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "black");
            writer.WriteStartElement(Prefixes.DrawingML, "alpha", Namespaces.DrawingML);
            writer.WriteAttributeString("val", "40000");
            writer.WriteEndElement();//alpha
            writer.WriteEndElement();//prstClr
            writer.WriteEndElement();//outerShdw
            writer.WriteEndElement();//effectLst

            // scene3d
            writer.WriteStartElement(Prefixes.DrawingML, "scene3d", Namespaces.DrawingML);
            writer.WriteStartElement(Prefixes.DrawingML, "camera", Namespaces.DrawingML);
            writer.WriteAttributeString("prst", "orthographicFront");
            writer.WriteEndElement();//camera
            writer.WriteStartElement(Prefixes.DrawingML, "lightRig", Namespaces.DrawingML);
            writer.WriteAttributeString("rig", "threePt");
            writer.WriteAttributeString("dir", "t");
            writer.WriteEndElement();//lightRig
            writer.WriteEndElement();//scene3d

            // sp3d
            writer.WriteStartElement(Prefixes.DrawingML, "sp3d", Namespaces.DrawingML);
            writer.WriteStartElement(Prefixes.DrawingML, "bevelT", Namespaces.DrawingML);
            writer.WriteEndElement();//bevelT
            writer.WriteStartElement(Prefixes.DrawingML, "bevelB", Namespaces.DrawingML);
            writer.WriteEndElement();//bevelB
            writer.WriteEndElement();//sp3d

            writer.WriteEndElement();//spPr
        }
    }
}
